package com.zzyl.nursing.member.controller;

import com.zzyl.common.core.domain.AjaxResult;
import com.zzyl.common.core.domain.R;
import com.zzyl.nursing.member.domain.Reservation;
import com.zzyl.nursing.member.dto.ReservationPageDto;
import com.zzyl.nursing.member.service.MemberReservationService;
import com.zzyl.nursing.member.vo.AppointmentVo;
import com.zzyl.nursing.member.vo.ReservationVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/member/reservation")
public class MemberReservationController {

    @Autowired
    private MemberReservationService memberReservationService;

    /**
     * 统计预约取消数量
     *
     * @return
     */
    @GetMapping("/cancelled-count")
    public R<Long> cancelledCount() {
        return R.ok(memberReservationService.cancelledCount());
    }

    /**
     * 统计预约时间段内预约数量
     *
     * @param time
     * @return
     */
    @GetMapping("/countByTime")
    public R<List<AppointmentVo>> countByTime(long time) {
        return R.ok(memberReservationService.countByTime(time));
    }

    /**
     * 添加预约
     *
     * @return
     */
    @PostMapping
    public AjaxResult reservation(@RequestBody Reservation reservation) {
        memberReservationService.reservation(reservation);
        return AjaxResult.success();
    }

    /**
     * 分页查询预约
     *
     * @return
     */
    @GetMapping("/page")
    public R<ReservationVo> page(ReservationPageDto reservation) {
        return R.ok(memberReservationService.page(reservation));
    }

    @PutMapping("/{id}/cancel")
    public AjaxResult cancel(@PathVariable Integer id) {
        memberReservationService.cancel(id);
        return AjaxResult.success();
    }
}
